package com.sxpi.zixun.controller.questions;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.bo.QuestionsBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.Questions;
import com.sxpi.zixun.service.questions.IQuestionsService;
import com.sxpi.zixun.vo.QuestionsVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/12 12:51
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章管理",tabname="kss_questions")
public class QuestionsController extends BaseController {

    private final IQuestionsService questionsService;

    /**
     * 查询文章管理列表信息
     * @return
     */
    @PostMapping("/questions/list")
    @PugDoc(name="查询文章管理列表信息")
    public List<QuestionsBo> findQuestionsList() {
        return questionsService.findQuestionsList();
    }

    /**
     * 查询文章管理列表信息并分页
     * @param questionsVo
     * @return
     */
    @PostMapping("/questions/load")
    @PugDoc(name="查询文章管理列表信息并分页")
    public IPage<QuestionsBo> findQuestionss(@RequestBody QuestionsVo questionsVo) {
        return questionsService.findQuestionsPage(questionsVo);
    }

    /**
     * 根据文章管理id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/questions/get/{id}")
    @PugDoc(name="根据文章管理id查询明细信息")
    public QuestionsBo getQuestionsById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionsService.getQuestionsById(new Long(id));
    }

    /**
     * 保存和修改文章管理
     * @param questions
     * @return
     */
    @PostMapping("/questions/saveupdate")
    @PugDoc(name="保存和修改文章管理")
    public QuestionsBo saveUpdateQuestions(@RequestBody Questions questions) {
        return questionsService.saveUpdateQuestions(questions);
    }

    /**
     * 根据文章管理id删除文章管理
     * @param id
     * @return
     */
    @PostMapping("/questions/delete/{id}")
    @PugDoc(name="根据文章管理id删除文章管理")
    public int deleteQuestionsById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return questionsService.deleteQuestionsById(new Long(id));
    }

    /**
     * 根据文章管理ids批量删除文章管理
     * @param questionsVo
     * @return
     */
    @PostMapping("/questions/delBatch")
    @PugDoc(name="根据文章管理ids批量删除文章管理")
    public boolean delQuestions(@RequestBody QuestionsVo questionsVo) {
        Vsserts.isNullEx(questionsVo, ResultStatusEnum.ID_NOT_EMPTY);
        return questionsService.delBatchQuestions(questionsVo.getBatchIds());
    }

}
